package com.lcc.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Slf4j
@Component
@Aspect
public class MyAspect2 {

    //@Pointcut("execution(* com.lcc.service.DeptLogService.*(..))")
    /*@Pointcut("execution(* com.lcc.service.impl.DeptServiceImpl.*(..))")
    public void pt() {}

    @Before("pt()") //Before等其他通知使用 JoinPoint
    public void before(JoinPoint joinPoint) { //前置通知拿不到返回值
        log.info("MyAspect2...before...");
    }

    @Around("pt()") //环绕通知中使用ProceedingJoinPoint
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("MyAspect2 around before ... ");

        //1. 获取 目标对象的类名。
        Object target = joinPoint.getTarget();
        log.info("目标对象的类名"+target);

        //2. 获取 目标方法的方法名。
        String methodName = joinPoint.getSignature().getName();
        log.info("目标方法的方法名"+methodName);

        //3. 获取 目标方法运行时传入的参数
        Object[] methodArgs = joinPoint.getArgs();
        log.info("目标方法运行时传入的参数" + Arrays.toString(methodArgs));

        //4. 放行 目标方法执行
        Object result = joinPoint.proceed();

        //5. 获取 目标方法运行的返回值
        log.info("目标方法运行的返回值"+result);

        log.info("MyAspect2 around after ... ");
        return true;
    }*/
}
